﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Yaml.Serialization;

namespace Medhurst.Unity.Configuration.Models
{
    public class Aliases
    {
        public Dictionary<string,string> Interfaces { get; set; }

        public Dictionary<string,string> Implementations { get; set; }

        public Dictionary<string, string> Converters { get; set; }

        public static Aliases Load(string yamlString)
        {
            var serializer = new YamlSerializer();
            var res = serializer.Deserialize(yamlString, typeof(Aliases));
            return res.FirstOrDefault() as Aliases;
        }

        public static Aliases LoadFile(string path)
        {
            var serializer = new YamlSerializer();
            var res = serializer.DeserializeFromFile(path, typeof(Aliases));
            return res.FirstOrDefault() as Aliases;
        }

#if DEBUG
        
        // only used for unit testing so no point
        // adding to release builds

        public string Serialize()
        {
            var serializer = new YamlSerializer();
            return serializer.Serialize(this);
        }

        public void SerializeToFile(string path)
        {
            var serializer = new YamlSerializer();
            serializer.SerializeToFile(path, this);
        }
#endif

    }
}
